package com.gzw.scm.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.view.View;
import android.view.ViewGroup;

import com.gzw.scm.base.BaseFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/13.
 */
public class MainViewPagerAdapter extends FragmentPagerAdapter {
    private List<Class> lsFragment = new ArrayList<>();

    public MainViewPagerAdapter(FragmentManager fragmentManager, List<Class> _lsFragment) {
        super(fragmentManager);
        this.lsFragment = _lsFragment;
    }

    @Override
    public Fragment getItem(int position) {
        BaseFragment baseFragment = null;
        try {
            String s = lsFragment.get(position).getName();
            Class clazz = Class.forName(s);
            baseFragment = (BaseFragment) clazz.newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return baseFragment;
    }
    @Override
    public int getCount() {
        return lsFragment.size();
    }

    @Override
    /**这个方法，是从ViewGroup中移出当前View**/
    public void destroyItem(View container, int position, Object object){
        ((ViewGroup) container).removeView((View) object);
        object=null;

    }
}